<?php

namespace app\mysql;

/**
 * 公共部分
 */
class Common
{
    //
    private $pdo;
    private $sql;

    /**
     * 生成所需的pdo对象
     */
    public function __construct()
    {
        $database = include __DIR__ . '/../../config/database.php'; // 兼容命令行模式
        $dsn = $database['type'] . ":host=" . $database['hostname'] . ";dbname=" . $database['database'];
        try {
            $this->pdo = new \PDO($dsn, $database['username'], $database['password'], array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET
          NAMES'UTF8';", ));
        } catch (\Exception $e) {
            echo $e->getMessage();
            return;
        }
    }
    /**
     * 注入所有事件
     *
     * @return void
     */
    public function runAll()
    {
    }

    /**
     * 后置操作
     */
    private function afterAction()
    {
        $stmt = $this->pdo->prepare($this->sql);
        $res = $stmt->execute();
        if ($res) {
            return true;
        } else {
            return false;
        }
    }
}
